<?php
require('../../../lib/base.php');
$base=new base(array('web','mail'));
$captcha=$base->library('captcha');
$helper=$base->library('helper');
if(!$captcha->check($base->post('captcha',true))){
	$helper->SMessage(5,$_SERVER['HTTP_REFERER'],"no","验证码错误,请正确输入.",true);
	exit();
}
$mail=strtolower($base->post('mail',true));
$name=$base->post('name',true);
$password=$base->post('password',true);
$IDcard=$base->post('IDcard',true);
$phone=$base->post('phone',true);
$time=$base->runtime;
$IP=ip2long($_SERVER["REMOTE_ADDR"]);
if(!$helper->CMail($mail)||(strlen($password)<6)||(strlen($password)>32)||!isset($name)||(strlen($IDcard)<15)||(!$helper->CPhone($phone))){
	$helper->SMessage(5,$_SERVER['HTTP_REFERER'],'warn',"您输入注册信息有误,请按照规定输入.",true);
	exit();
}
$key=$helper->uniquestr();
$member=$base->model('member');
if(count($member->GMember(array('where'=>array('mail ='=>$mail))))>0){
	$helper->SMessage(5,$_SERVER['HTTP_REFERER'],"info","邮箱已被注册,5秒后返回上一页",true);
	exit();
}
$mysql=$base->library('mysql');
$information=$base->model('information');
$mysql->startTrans();
$affected=$member->IMember(array('mail'=>$mail,'password'=>$password,'role'=>2,'key'=>$key,'ip'=>$IP,'date'=>$time,'locked'=>1),1);
$mation=$information->IMation(array('member'=>$affected,'account'=>'','name'=>$name,'IDcard'=>$IDcard,'phone'=>$phone,'msn'=>'','qq'=>'','date'=>$time,'ip'=>$IP));
if(($mation==0)||($affected==0)){
	$mysql->rollback();
	$helper->SMessage(5,$_SERVER['HTTP_REFERER'],"no","您输入注册信息有误,5秒后返回上一页",true);
	exit();
}else{
	$mysql->commit();
}
$config=$base->model('config');
$tpl=reset($config->GConfig(array('where'=>array('label='=>'mail','name='=>'activation'))));
$tpl['value']=preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'",$tpl['value']);
$tpl=unserialize($tpl['value']);
$email=$base->library('email');
$email->IsSMTP();
$email->AddAddress($mail,$name);
$email->Subject =$tpl['subject'];
$email->MsgHTML($config->parse($tpl['content'],array('name'=>$name,'code'=>$key)));
$email->Send();
$entry=array('163'=>'mail.163.com','139'=>'mail.10086.cn','sohu'=>'mail.sohu.com','tom'=>'mail.tom.com','189'=>'mail.189.cn','126'=>'www.126.com','gmail'=>'gmail.google.com'
,'sina'=>'mail.sina.com.cn','hotmail'=>'www.hotmail.com','live'=>'www.hotmail.com','sogou'=>'mail.sogou.com','qq'=>'mail.qq.com','yahoo'=>'mail.cn.yahoo.com','eyou'=>'www.eyou.com','21cn'=>'mail.21cn.com'
,'188'=>'www.188.com','yeah'=>'www.yeah.net','foxmail'=>'www.foxmail.com','wo'=>'mail.wo.com.cn','263'=>'www.263.net');
$data=array('mail'=>$mail);
foreach($entry as $key=>$value){
	if(strpos($mail,$key.'')!==false){$data['go']='http://'.$value;break;}
}
$sort=$base->model('sort');
$data['menu']=$sort->GSort(array('where'=>array('label='=>'IndexMenu','locked='=>0),'order'=>array('sequence'=>'ASC')));
$base->set($data);
$base->view('view/mailok.php');
?>